import { Metadata } from "next" import Link from "next/link" import { Separator } from "@/components/ui/separator" import { SidebarNav } from "@/components/layout/sidebar-nav" import { formatDate } from "@/lib/utils" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { ArrowLeft, Clock, AlertTriangle, CheckCircle, XCircle, AlertCircle, Calendar, CalendarDays } from "lucide-react" import { RfqsLastView } from "@/db/schema" import { findRfqLastById } from "@/lib/rfq-last/service" import { differenceInDays } from "date-fns" import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert" import { DueDateEditButton } from "@/lib/rfq-last/due-date-edit-button" export const metadata: Metadata = { title: "견적 목록 상세", } export default async function RfqLayout({ children, params, }: { children: React.ReactNode params: { lng: string, id: string } }) { // 1) URL 파라미터에서 id 추출, Number로 변환 const resolvedParams = await params const lng = resolvedParams.lng const rfqId = parseInt(resolvedParams.id, 10); if (!rfqId || isNaN(rfqId) || rfqId <= 0) { return (
오류 유효하지 않은 RFQ입니다.
); } // 2) DB에서 해당 협력업체 정보 조회 const rfq: RfqsLastView | null = await findRfqLastById(rfqId) // 3) 사이드바 메뉴 const sidebarNavItems = [ { title: "견적 문서관리", href: `/${lng}/evcp/rfq-last/${rfqId}`, }, { title: "RFQ 발송", href: `/${lng}/evcp/rfq-last/${rfqId}/vendor`, }, ] // Due Date 상태 계산 함수 const getDueDateStatus = (dueDate: Date | string | null) => { if (!dueDate) return null; const now = new Date(); const due = new Date(dueDate); const daysLeft = differenceInDays(due, now); if (daysLeft < 0) { return { icon: , text: `${Math.abs(daysLeft)}일 지남`, className: "text-red-600", bgClassName: "bg-red-50" }; } else if (daysLeft === 0) { return { icon: , text: "오늘 마감", className: "text-orange-600", bgClassName: "bg-orange-50" }; } else if (daysLeft <= 3) { return { icon: , text: `${daysLeft}일 남음`, className: "text-amber-600", bgClassName: "bg-amber-50" }; } else if (daysLeft <= 7) { return { icon: , text: `${daysLeft}일 남음`, className: "text-blue-600", bgClassName: "bg-blue-50" }; } else { return { icon: , text: `${daysLeft}일 남음`, className: "text-green-600", bgClassName: "bg-green-50" }; } }; const dueDateStatus = rfq?.dueDate ? getDueDateStatus(rfq.dueDate) : null; const getRfqCategory = (rfqCode: string | null | undefined): string => { if (!rfqCode || rfqCode.length === 0) return 'itb'; // 기본값 const firstChar = rfqCode[0].toUpperCase(); switch (firstChar) { case 'I': return 'itb'; case 'R': return 'rfq'; case 'F': return 'general'; default: return 'itb'; // 기본값 } }; return ( <>
{/* 제목과 버튼을 같은 라인에 배치 */}

{rfq ? rfq.rfqTitle ? `견적 상세 관리 ${rfq.rfqCode ?? ""} | ${rfq.rfqTitle}` : `견적 상세 관리 ${rfq.rfqCode ?? ""}` : "Loading RFQ..."}

{/* 생성일과 마감일 표시 */} {rfq && (
{/* 생성일 */}
생성일: {formatDate(rfq.createdAt, "KR")}
{/* 구분선 */}
{/* 마감일 */}
마감일: {rfq.dueDate ? ( <> {formatDate(rfq.dueDate, "KR")} {dueDateStatus && (
{dueDateStatus.icon} {dueDateStatus.text}
)} ) : ( <> 미설정 )}
)}
{children}
) }